
<style>
.bbline1{color:#999;}
.messageBox .unread{font-weight:bold;color:#333;}
.ui-portlet {margin:0 0 20px;background: #FFF;overflow: hidden; border:1px solid #ddd;}
ul.ui-portlet-list > li:last-child{border-bottom: 0 none !important;}

</style>
<div class="ui-portlet-header">
	      <span class="title">站内消息中心</span>            
</div>

        <div class="mb10">
       	<a class="btn btn-primary" target="_blank" href="{{$this->Html->url(array('action'=>'add'))}}"><i class="fa fa-file-o"></i> 发送短消息</a>
       </div>
       
<div class="messageBox btline2"><!--messageBox start-->
<table class="table border tbordernone" style="width:100%;">
	<thead><tr><th>消息标题</th><th>发送时间</th><th>操作</th></tr></thead>
    {{loop $datalist $item}}    	 	
                  <tbody><tr class="bbline1 {{if !$item['Shortmessage']['haveread']}}unread{{/if}}">
                    <td width="60%" class="read-message" data-id="{{$item['Shortmessage']['id']}}">
                        {{$item['Shortmessage']['title']}}
					</td><td width="25%" >
					<small>{{$item['Shortmessage']['created']}}</small>
                    </td>
                    <td width="15%" >
                      <button type="button" data-id="{{$item['Shortmessage']['id']}}" class="btn btn-primary btn-xs read-message">{{__('查看')}}</button>
                    </td>
                  </tr>
                  <tr class="bg1 {{if $_REQUEST['id']!=$item['Shortmessage']['id']}}hidden{{/if}} message-body" id="message-body-{{$item['Shortmessage']['id']}}">
                  	 <td class="p20" colspan="3">
                  	 
                  	 	<p>{{nl2br($item['Shortmessage']['message'])}}</p>
                  	 	{{if $item['Shortmessage']['msgfromid']}}
                  	 	<p><a target="_blank" class="btn btn-default btn-xs" href="/shortmessages/add?receiverid={{$item['Shortmessage']['msgfromid']}}">回复</a></p>
                  	 	{{/if}}
                  	 </td>
                  </tr>
         </tbody>
    {{/loop}}
</table>
    <br/>
    {{$page_navi}}    
    <br/>
    <portlet model="Announcement" cached="900" showpages="0" title="系统公告"
info="fields[]=Announcement.id&fields[]=Announcement.name&fields[]=Announcement.created"
		portlet="default" conditons="published=1" list_tpl="inner" limit="12" order="id desc" >
			<li style="border-bottom:1px solid #ddd;padding:10px 20px;">
				<p><a target="_blank" href="/announcements/view/{{$item['id']}}"> {{$item['name']}}</a> </p>
				<p><small>{{$item['created']}}</small></p>
            </li>
		</portlet> 
                
</div>
<script>
$(function(){
	{{if $_REQUEST['id']}}
		$.ajax({
			type:'get',
			url:BASEURL+'/shortmessages/read/{{$_REQUEST['id']}}',
			success:function(data){
				//do nothing;
			},
			dataType:'html'		
		});
	{{/if}}


	$('.read-message').click(function(){
		var msgid = $(this).data('id');
		var title = $(this).parents('tr:first');
		var body = title.next();
		if(body.hasClass('hidden')){
			$('.message-body').addClass('hidden');
			body.removeClass('hidden');
			if(title.hasClass('unread')){
				title.removeClass('unread');
				$.ajax({
					type:'get',
					url:BASEURL+'/shortmessages/read/'+msgid,
					success:function(data){
						//do nothing;
					},
					dataType:'html'		
				});
			}			
		}
		else{
			body.addClass('hidden')
		}		
	});
})
</script>
